package com.ruoyi.common.utils;

import com.ruoyi.common.utils.uuid.UUID;

import java.text.SimpleDateFormat;
import java.util.Date;

public class NumberUtil {

    /**
     * 生成规则设备编号:设备类型+五位编号（从1开始，不够前补0）
     *
     * @param equipmentType
     *                 设备类型
     * @param ymd
     *                 年月日
     * @param equipmentNo
     *                 最新设备编号
     * @return
     */
    public static String getNewEquipmentNo(String equipmentType,String ymd, String equipmentNo){
        String newEquipmentNo = equipmentType + ymd + "00001";

        if(equipmentNo != null && !equipmentNo.isEmpty()){
            int no = Integer.parseInt(equipmentNo);
            int newEquipment = ++no;
            newEquipmentNo = String.format(equipmentType + ymd + "%05d", newEquipment);
        }

        return newEquipmentNo;
    }

    public static String getNumber(String type,String number) {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateNowStr = sdf.format(d);
        String str = getNewEquipmentNo(type,dateNowStr,number);
        return str;
    }

    /**
     * mes生产队列-序列号
     * @param type
     * @return
     */
    public static String getSerialNumber(String type) {
        Date d = new Date();
        UUID uuid = UUID.randomUUID();
        String number = uuid.toString();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String dateNowStr = sdf.format(d);
        String str = type+dateNowStr+number;
        return str;
    }

    public static void main(String[] args) {

        System.out.println(getSerialNumber("mpq"));
    }
}
